import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Solution967 {
    public int[] numsSameConsecDiff(int n, int k) {
        List<Integer> list=new ArrayList<>();
        int[] f=new int[n];
        dfs(0,n,k,f,list);
        int[] ans=new int[list.size()];
        for (int i=0;i<list.size();i++){
            ans[i]=list.get(i);
        }
        return ans;
    }

    private void dfs(int t, int n, int k, int[] f, List<Integer> list) {
        if (t==n){
            int ans=0;
            for (int i=0;i<n;i++){
                ans=ans*10+f[i];
            }
            list.add(ans);
            return;
        }
        if (t==0){
            for (int i=1;i<=9;i++){
                f[t]=i;
                dfs(t+1,n,k,f,list);
            }
            if (n==1){
                f[t]=0;
                dfs(t+1,n,k,f,list);
            }
        }else {
            if (f[t-1]+k>=0 && f[t-1]+k<=9){
                f[t]=f[t-1]+k;
                dfs(t+1,n,k,f,list);
            }
            if (k!=0 && f[t-1]-k>=0 && f[t-1]-k<=9){
                f[t]=f[t-1]-k;
                dfs(t+1,n,k,f,list);
            }
        }
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution967().numsSameConsecDiff(2, 2)));
    }
}
